package com.rongmai.web.bo;

import com.rongmai.db.enums.UserRoleEnum;
import com.rongmai.db.vo.Page;
import com.rongmai.db.vo.UserVo;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class RecommendBo {

    @Resource
    private UserBo userBo;

    public List<UserVo> getRecommendUser(UserRoleEnum roleEnum) {
        if (roleEnum == null) {
            return Collections.emptyList();
        }
        UserVo userVo = new UserVo();
        userVo.setRole(roleEnum.name());
        userVo.setPageSize(5);
        Page<UserVo> page = userBo.pageUser(userVo);
        return page.getList();
    }

    public List<UserVo> myCompanyUser(Integer companyId) {
        List<UserVo> userVos = userBo.myCompanyUser(companyId);
        if (!CollectionUtils.isEmpty(userVos) && userVos.size() > 4) {
            return userVos.subList(0,5);
        }
        return userVos;
    }
}
